
#include <Game/Game.h>
#include <Skills/typeDefense.h>
#include <include/sdk/misc.h>
#include "Skills/automatic.h"

Actor::Actor() : Entity() {
    this->setName("Actor");
    this->learnSkill(new skill::DescendCoolDown);
    this->learnSkill(new skill::DeathCalulation);
}

const Point &Actor::pos() const {
    return m_pos;
}

void Actor::setPos(const Point &pos) {
    g->entityManager.setPos(this, pos);
    this->m_pos = pos;
}

Json::Value Actor::toJson() {
    Json::Value root = Entity::toJson();
    root["pos"] = this->pos().to_string();
    return root;
}

int Actor::squaredDistanceTo(const Actor *other) const {
    return (this->pos() - other->pos()).getSquaredEuclideanLength();
}

int Actor::getDamage(Actor *foe, const double power) {
    double damage = std::stoi(this->properties["attack"]);
    int defense = std::stoi(foe->properties["defense"]);
    if (foe->hasSkill("ShieldingBuff"))
        defense += (dynamic_cast<skill::ShieldingBuff*>(foe->skillList["ShieldingBuff"]))->power;
    if (this->hasSkill("DecAttackBuff")) damage *= AttackRate;
    damage *= power;
    damage *= defenseBaseValue / (defenseBaseValue + defense);
    return int(damage + EPS);
}

void Actor::projectDamage(Actor *foe, const double power) {
    int x = std::stoi(foe->properties["hp"]);
    x -= getDamage(foe, power);
    foe->properties["hp"] = std::to_string(x);
}

